<template>
    <div class="todo_item">
        <label>
            <input 
                type="checkbox" 
                :checked="todo.isDone" 
                @change="handleChange(todo.id)"
            >
            {{todo.task}}
        </label>
        <button @click="delItem(todo.id)">删除该任务</button>
        <hr>
    </div>
</template>

<script>
export default {
    name: 'TodoItem',
    props: ['todo', 'getChecked', 'removeItem'],
    methods: {
        handleChange(id) {
            // console.log('该任务的id是：', id);
            this.getChecked(id);
        },
        delItem(id) {
            if(confirm('你确定要删除该项任务吗？')) {
                // console.log('该任务的id是：', id);
                this.removeItem(id);
            }
        }
    }
}
</script>

<style scoped>
.todo_item {
    width: 100%;
    padding: 5px 0 5px 10px;
    box-sizing: border-box;
}

button {
    background-color: coral;
    outline: none;
    border: none;
    border-radius: 4px;
    padding: 5px 10px;
    box-sizing: border-box;
    cursor: pointer;
    color: #fff;
    float: right;
    margin-right: 5px;
    display: none;
}

.todo_item:hover button {
    display: inline-block;
}
</style>